package lwk.juc.sup;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author:lwk
 * @create: 2022-08-13 09:50
 * @Description: 测试减法计数器
 */
public class TestCountDownLanch {
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(5);

        for (int i = 1; i <= 5; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"====> 走了");
                countDownLatch.countDown();
            },String.valueOf(i)).start(); // 走一个人，计数器减1
        }

        countDownLatch.await(); // 等待计数器归零，阻塞
        System.out.println(countDownLatch.getCount());
        //TimeUnit.SECONDS.sleep(1);

        System.out.println("人走了，关门！");

    }
}
